package com.fast.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

public abstract class AbstracterController {

	protected final Logger logger = LoggerFactory.getLogger(getClass());
	protected Map<String, String> model = new HashMap<String, String>();
	protected static final String EMPTY_PATH = "";
	protected static final String USER_ID = "user_id";

	public abstract String getRootPath();

	protected boolean checkUserLogin(String userId, HttpSession httpSession) {
		return userId.equals(httpSession.getAttribute(USER_ID));
	}

	protected String page(String page){
		return getRootPath() + page;
	}
	/**
	 * 根据给的jsp目录及页面跳转到jsp
	 * 
	 * @param page
	 *            jsp 页面名称
	 * @return
	 */
	/**
	 * 将信息传递互指定的页面
	 * 
	 * @param page
	 * @return
	 */
	protected ModelAndView view(String page) {
		if (null != model && 0 < model.size()) {
			return new ModelAndView(getRootPath() + page, model);
		}
		return new ModelAndView(getRootPath() + page);
	}

	/**
	 * 将数值转换为MAP
	 * 
	 * @param result
	 * @return
	 */
	protected Map<String, String> ajaxMap(boolean flag) {
		Map<String, String> map = new HashMap<String, String>(1);
		String result = flag ? "true" : "false";
		map.put("success", result);
		return map;
	}
}
